package com.swz.dcrm.ui.viewmodel;



import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;


import com.swz.dcrm.db.AppDatabase;
import com.swz.dcrm.ui.analyze.AnalyzeType5Fragment;

import retrofit2.Retrofit;


/**
 * @author xh
 */
public class ViewModelFactory implements ViewModelProvider.Factory  {



    private Retrofit mRetrofit;
    private AppDatabase appDatabase;

    public ViewModelFactory(Retrofit r, AppDatabase appDatabase){

       this.mRetrofit=r;
       this.appDatabase=appDatabase;

    }
    @NonNull
    @Override
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {

        if(modelClass.isAssignableFrom(MainViewModel.class)){
            return (T) new MainViewModel(mRetrofit);
        } else if (modelClass.isAssignableFrom(HomeViewModel.class)) {
            return (T) new HomeViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(TodayPlanViewModel.class)) {
            return (T) new TodayPlanViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(CustomerManagementViewModel.class)) {
            return (T) new CustomerManagementViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(ScheduleViewModel.class)) {
            return (T) new ScheduleViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(AnnouncementViewModel.class)) {
            return (T) new AnnouncementViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(StaffViewModel.class)) {
            return (T) new StaffViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(GroupViewModel.class)) {
            return (T) new GroupViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(CarBrandViewModel.class)) {
            return (T) new CarBrandViewModel(mRetrofit,appDatabase);
        }else if (modelClass.isAssignableFrom(CarManagementViewModel.class)) {
            return (T) new CarManagementViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(ApprovalViewModel.class)) {
            return (T) new ApprovalViewModel(mRetrofit);
        }else if (modelClass.isAssignableFrom(AnalyzeViewModel.class)) {
            return (T) new AnalyzeViewModel(mRetrofit);
        }
        return null;
    }
}
